// d导入axios工具包
import instance from "@/utils/axios.js";

// 获取用户频道列表
function getChannels() {
  return instance({
    url: "/v1_0/channels",
    method: "get"
  });
}
// 导出频道列表接口
export { getChannels };

// 获取频道新闻推荐
function getArticles({ channel_id, timestamp }) {
  return instance({
    url: "/v1_1/articles",
    method: "get",
    params: {
      channel_id,
      timestamp,
      with_top: 1
    }
  });
}
// 导出接口
export { getArticles };

// 获取文章详情
function getDetails(id) {
  return instance({
    url: "/v1_0/articles/" + id,
    method: "get"
  });
}
// 导出接口
export { getDetails };

// 关注用户
function followUser({ target }) {
  return instance({
    url: "/v1_0/user/followings",
    method: "post",
    data: { target }
  });
}
export { followUser };
// 取消关注用户
function unFollowUser(target) {
  return instance({
    url: `/v1_0/user/followings/${target}`,
    method: "delete"
  });
}
export { unFollowUser };

// 点赞文章
function addPraise({ target }) {
  return instance({
    url: "/v1_0/article/likings",
    method: "post",
    data: { target }
  });
}
export { addPraise };
// 取消点赞
function deletePraise(target) {
  return instance({
    url: `/v1_0/article/likings/${target}`,
    method: "delete"
  });
}
export { deletePraise };

// 不喜欢文章
function addLike({ target }) {
  return instance({
    url: "/v1_0/article/dislikes",
    method: "post",
    data: { target }
  });
}
export { addLike };
// 取消不喜欢
function deleteLike(target) {
  return instance({
    url: `/v1_0/article/dislikes/${target}`,
    method: "delete"
  });
}
export { deleteLike };

// 获取联想建议
function getSuggestion({ q }) {
  return instance({
    url: "/v1_0/suggestion",
    method: "get",
    params: { q }
  });
}
export { getSuggestion };
// 获取搜索结果接口
function getsearchResults({ q }) {
  return instance({
    url: "/v1_0/search",
    method: "get",
    params: { q }
  });
}
// 导出接口
export { getsearchResults };

// 获取用户搜索记录
function searchRecords() {
  return instance({
    url: "/v1_0/search/histories",
    method: "get"
  });
}
export { searchRecords };

// 删除用户搜索记录接口
function deleteSearchRecords() {
  return instance({
    url: "/v1_0/search/histories",
    method: "delete"
  });
}
export { deleteSearchRecords };
